package com.j256.ormlite.table;

import com.j256.ormlite.dao.BaseDaoImpl;
import com.j256.ormlite.db.DatabaseType;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.misc.BaseDaoEnabled;
import com.j256.ormlite.misc.SqlExceptionUtil;
import com.j256.ormlite.support.ConnectionSource;
import java.lang.reflect.Constructor;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class TableInfo<T, ID>
{
  private static final FieldType[] NO_FOREIGN_COLLECTIONS = new FieldType[0];
  private final BaseDaoImpl<T, ID> baseDaoImpl;
  private final Constructor<T> constructor;
  private final Class<T> dataClass;
  private Map<String, FieldType> fieldNameMap;
  private final FieldType[] fieldTypes;
  private final boolean foreignAutoCreate;
  private final FieldType[] foreignCollections;
  private final FieldType idField;
  private final String tableName;

  public TableInfo(DatabaseType paramDatabaseType, BaseDaoImpl<T, ID> paramBaseDaoImpl, DatabaseTableConfig<T> paramDatabaseTableConfig)
    throws SQLException
  {
    this.baseDaoImpl = paramBaseDaoImpl;
    this.dataClass = paramDatabaseTableConfig.getDataClass();
    this.tableName = paramDatabaseTableConfig.getTableName();
    this.fieldTypes = paramDatabaseTableConfig.getFieldTypes(paramDatabaseType);
    Object localObject = null;
    boolean bool = false;
    int i = 0;
    for (FieldType localFieldType2 : this.fieldTypes)
    {
      if ((localFieldType2.isId()) || (localFieldType2.isGeneratedId()) || (localFieldType2.isGeneratedIdSequence()))
      {
        if (localObject != null)
          throw new SQLException("More than 1 idField configured for class " + this.dataClass + " (" + localObject + "," + localFieldType2 + ")");
        localObject = localFieldType2;
      }
      if (localFieldType2.isForeignAutoCreate())
        bool = true;
      if (localFieldType2.isForeignCollection())
        i++;
    }
    this.idField = localObject;
    this.constructor = paramDatabaseTableConfig.getConstructor();
    this.foreignAutoCreate = bool;
    if (i == 0)
      this.foreignCollections = NO_FOREIGN_COLLECTIONS;
    while (true)
    {
      return;
      this.foreignCollections = new FieldType[i];
      int m = 0;
      for (FieldType localFieldType1 : this.fieldTypes)
        if (localFieldType1.isForeignCollection())
        {
          this.foreignCollections[m] = localFieldType1;
          m++;
        }
    }
  }

  public TableInfo(ConnectionSource paramConnectionSource, BaseDaoImpl<T, ID> paramBaseDaoImpl, Class<T> paramClass)
    throws SQLException
  {
    this(paramConnectionSource.getDatabaseType(), paramBaseDaoImpl, DatabaseTableConfig.fromClass(paramConnectionSource, paramClass));
  }

  private static <T, ID> void wireNewInstance(BaseDaoImpl<T, ID> paramBaseDaoImpl, T paramT)
  {
    if ((paramT instanceof BaseDaoEnabled))
      ((BaseDaoEnabled)paramT).setDao(paramBaseDaoImpl);
  }

  public T createObject()
    throws SQLException
  {
    try
    {
      BaseDaoImpl localBaseDaoImpl = this.baseDaoImpl;
      ObjectFactory localObjectFactory = null;
      if (localBaseDaoImpl != null)
        localObjectFactory = this.baseDaoImpl.getObjectFactory();
      if (localObjectFactory == null);
      Object localObject2;
      for (Object localObject1 = this.constructor.newInstance(new Object[0]); ; localObject1 = localObject2)
      {
        wireNewInstance(this.baseDaoImpl, localObject1);
        return localObject1;
        localObject2 = localObjectFactory.createObject(this.constructor, this.baseDaoImpl.getDataClass());
      }
    }
    catch (Exception localException)
    {
      throw SqlExceptionUtil.create("Could not create object for " + this.constructor.getDeclaringClass(), localException);
    }
  }

  public Constructor<T> getConstructor()
  {
    return this.constructor;
  }

  public Class<T> getDataClass()
  {
    return this.dataClass;
  }

  public FieldType getFieldTypeByColumnName(String paramString)
  {
    if (this.fieldNameMap == null)
    {
      HashMap localHashMap = new HashMap();
      for (FieldType localFieldType3 : this.fieldTypes)
        localHashMap.put(localFieldType3.getColumnName().toLowerCase(), localFieldType3);
      this.fieldNameMap = localHashMap;
    }
    FieldType localFieldType1 = (FieldType)this.fieldNameMap.get(paramString.toLowerCase());
    if (localFieldType1 != null)
      return localFieldType1;
    for (FieldType localFieldType2 : this.fieldTypes)
      if (localFieldType2.getFieldName().equals(paramString))
        throw new IllegalArgumentException("You should use columnName '" + localFieldType2.getColumnName() + "' for table " + this.tableName + " instead of fieldName '" + localFieldType2.getFieldName() + "'");
    throw new IllegalArgumentException("Unknown column name '" + paramString + "' in table " + this.tableName);
  }

  public FieldType[] getFieldTypes()
  {
    return this.fieldTypes;
  }

  public FieldType[] getForeignCollections()
  {
    return this.foreignCollections;
  }

  public FieldType getIdField()
  {
    return this.idField;
  }

  public String getTableName()
  {
    return this.tableName;
  }

  public boolean hasColumnName(String paramString)
  {
    FieldType[] arrayOfFieldType = this.fieldTypes;
    int i = arrayOfFieldType.length;
    for (int j = 0; j < i; j++)
      if (arrayOfFieldType[j].getColumnName().equals(paramString))
        return true;
    return false;
  }

  public boolean isForeignAutoCreate()
  {
    return this.foreignAutoCreate;
  }

  public boolean isUpdatable()
  {
    return (this.idField != null) && (this.fieldTypes.length > 1);
  }

  public String objectToString(T paramT)
  {
    StringBuilder localStringBuilder = new StringBuilder(64);
    localStringBuilder.append(paramT.getClass().getSimpleName());
    FieldType[] arrayOfFieldType = this.fieldTypes;
    int i = arrayOfFieldType.length;
    int j = 0;
    while (j < i)
    {
      FieldType localFieldType = arrayOfFieldType[j];
      localStringBuilder.append(' ').append(localFieldType.getColumnName()).append("=");
      try
      {
        localStringBuilder.append(localFieldType.extractJavaFieldValue(paramT));
        j++;
      }
      catch (Exception localException)
      {
        throw new IllegalStateException("Could not generate toString of field " + localFieldType, localException);
      }
    }
    return localStringBuilder.toString();
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.j256.ormlite.table.TableInfo
 * JD-Core Version:    0.6.2
 */